package com.crowntit.config;

import com.crowntit.infrastructure.gateway.IGroupBuyMarketService;
import com.crowntit.infrastructure.gateway.IWeixinApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;

@Slf4j
@Configuration
public class retrofit2Config {

    private static final String BASE_URL = "https://api.weixin.qq.com/";

    @Value("${gbm.api-url}")
    private String groupBuyMarketApiBaseUrl;

    @Bean
    public Retrofit retrofit() {
        return new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(JacksonConverterFactory.create()).build();
    }

    @Bean
    public IWeixinApiService weixinApiService(Retrofit retrofit) {
        return retrofit.create(IWeixinApiService.class);
    }

    @Bean
    public IGroupBuyMarketService groupBuyMarketService() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(groupBuyMarketApiBaseUrl)
                .addConverterFactory(JacksonConverterFactory.create())
                .build();

        return retrofit.create(IGroupBuyMarketService.class);
    }
}
